package com.ggggeeennn.question.service.impl;

import com.ggggeeennn.question.domain.CourseQuestionCount;
import com.ggggeeennn.question.domain.Question;
import com.ggggeeennn.question.mapper.QuestionMapper;
import com.ggggeeennn.question.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 题库管理Service业务层处理
 * 
 * @author ggggeeennn
 * @date 2025-06-28
 */
@Service
public class QuestionServiceImpl implements QuestionService
{
    @Autowired
    private QuestionMapper questionMapper;


    @Override
    public List<CourseQuestionCount> countQuestionsByCourse(Question question) {
        return questionMapper.countQuestionsByCourse(question);

    }

    /**
     * 查询题库管理
     * 
     * @param questionId 题库管理主键
     * @return 题库管理
     */
    @Override
    public Question selectQuestionByQuestionId(Long questionId,Integer questionType)
    {
        //这里判断题目类型
        //判断题
        if(questionType==1){
            return questionMapper.selectJudgeQuestionByQuestionId(questionId);
        }else if(questionType==2){
            //选择题
            return questionMapper.selectMultiQuestionByQuestionId(questionId);
        }
        //填空题
        return questionMapper.selectFillQuestionByQuestionId(questionId);
    }

    /**
     * 查询题库管理列表
     * 
     * @param question 题库管理
     * @return 题库管理
     */
    @Override
    public List<Question> selectQuestionList(Question question)
    {
        return questionMapper.selectQuestionList(question);
    }

    /**
     * 新增题库管理
     * 
     * @param question 题库管理
     * @return 结果
     */
    @Override
    public int insertQuestion(Question question)
    {
        Integer questionType = Integer.parseInt(question.getQuestionType());
        if(questionType==1){
            return questionMapper.insertJudgeQuestion(question);
        }
        else if(questionType==2){
            return questionMapper.insertMultiQuestion(question);
        }
            return questionMapper.insertFillQuestion(question);
    }

    /**
     * 修改题库管理
     * 
     * @param question 题库管理
     * @return 结果
     */
    @Override
    public int updateQuestion(Question question)
    {
        Integer questionType = Integer.parseInt(question.getQuestionType());
        if(questionType==1){
            return questionMapper.updateJudgeQuestion(question);
        }
        else if(questionType==2){
            return questionMapper.updateMultiQuestion(question);
        }
        return questionMapper.updateFillQuestion(question);

    }

    /**
     * 批量删除题库管理
     * 
     * @param
     * @return 结果
     */
    @Override
    public int deleteQuestionByQuestionIds(Long[] judgeIds, Long[] multiIds, Long[] fillIds)
    {
        if(judgeIds!=null&&judgeIds.length>0){
            questionMapper.deleteJudgeQuestionByQuestionIds(judgeIds);
        }
        if(multiIds!=null&&multiIds.length>0){
            questionMapper.deleteMultiQuestionByQuestionIds(multiIds);
        }
        if(fillIds!=null&&fillIds.length>0){
            questionMapper.deleteFillQuestionByQuestionIds(fillIds);
        }
        return 1;


    }

    /**
     * 删除题库管理信息
     * 
     * @param questionId 题库管理主键
     * @return 结果
     */
    @Override
    public int deleteQuestionByQuestionId(Long questionId,Integer questionType)
    {
        if(questionType==1){
            return questionMapper.deleteJudgeQuestionByQuestionId(questionId);
        }
        else if(questionType==2){
            return questionMapper.deleteMultiQuestionByQuestionId(questionId);
        }
        return questionMapper.deleteFillQuestionByQuestionId(questionId);

    }
}
